home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows Expert
/
Windows Expert.iso
/
program
/
wintech1.zip
/
LEVARO.ZIP
/
NEWSTAT.C
next >
Wrap
Text File
|
1991-09-27
|
4KB
|
144 lines
/*
* NEWSTAT.C This file contains the static control window procedure
*/
#include <windows.h>
#include "statdll.h"
#include "newstat.h"
void StaticDraw(HWND hwnd,HDC hdc)
{
RECT clientRect;
HANDLE hCtrlText;
int iStrLength;
LPSTR lpstrText;
HFONT hOldFont;
WORD wStyle;
HBRUSH hCtlColorBr,hNewBrush;
COLORREF lOldColor;
HANDLE hParentInst;
HICON hIcon;
int iOldMapMode;
/* Obtain client window size and text */
GetClientRect(hwnd,&clientRect);
iStrLength = GetWindowTextLength(hwnd);
hCtrlText = GlobalAlloc(GMEM_FIXED,iStrLength + 1);
lpstrText = GlobalLock(hCtrlText);
GetWindowText(hwnd,lpstrText,iStrLength + 1);
/* Send the WM_CTLCOLOR message to the parent allowing it to alter */
/* the background brush and the text color. If a brush is not */
/* returned, used light gray as the background. */
hCtlColorBr = SendMessage(GetParent(hwnd),WM_CTLCOLOR,hdc,
MAKELONG(hwnd,CTLCOLOR_STATIC));
hNewBrush = hCtlColorBr ? hCtlColorBr : GetStockObjct(LTGRAY_BRUSH);
/* Paint the background with using the new brush. */
FillRect(hdc,&clientRect,hNewBrush);
/* If the static is an icon, the parent's icon is drawn but with */
/* the background that has already been drawn. */
if ((GetWindowLong(hwnd,GWL_STYLE) & 0xf) == SS_ICON)
{
hParentInst = GetWindowWord(hwnd,GWW_HINSTANCE);
hIcon = LoadIcon(hParentInst,lpstrText);
if (hIcon)
{
iOldMapMode = SetMapMode(hdc,MM_TEXT);
DrawIcon(hdc,clientRect.left,clientRect.top,hIcon);
SetMapMode(hdc,iOldMapMode);
}
GlobalFree(hCtrlText);
return;
}
/* The background mode is set to transparent so the text does not */
/* obliterate it, and the font is returned from the window extra */
/* byte area. */
SetBkMode(hdc,TRANSPARENT);
if (GET_STFONT != 0)
hOldFont = SelectObject(hdc,GET_STFONT);
/* Determine the style settings. */
wStyle = DT_VCENTER | DT_SINGLELINE;
if (IS_STYLE_SET(SS_CENTER))
wStyle |= DT_CENTER;
else if (IS_STYLE_SET(SS_RIGHT))
wStyle |= DT_RIGHT;
else wStyle |= DT_LEFT;
/* For indented text, display white text one pixel offset to the */
/* right and down. For raised text, the white text is offset to */
/* the left and up one pixel. */
if (IS_STYLE_SET(SS_INDENT))
{
lOldColor = SetTextColor(hdc,RGB(255,255,255));
OffsetRect(&clientRect,1,1);
DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
OffsetRect(&clientRect,-1,-1);
SetTextColor(hdc,lOldColor);
DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
}
else if (IS_STYLE_SET(SS_OUTDENT))
{
lOldColor = SetTextColor(hdc,RGB(255,255,255));
DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
SetTextColor(hdc,lOldColor);
OffsetRect(&clientRect,1,1);
DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
OffsetRect(&clientRect,-1,-1);
}
else
DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
if (GET_STFONT != 0 )
SelectObject(hdc,hOldFont);
GlobalFree(hCtrlText);
}
LONG FAR PASCAL StaticWndFn(HWND hwnd, WORD message,WORD wParam, LONG lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_SETFONT:
/* Store the returned font handle in the window extra bytes. */
SET_STFONT(wParam);
break;
case WM_ERASEBKGND:
/* The background is painted in the StaticDraw function. */
return TRUE;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
StaticDraw(hwnd,hdc);
EndPaint(hwnd,&ps);
return FALSE;
default:
break;
}
return DefWindowProc (hwnd,message,wParam,lParam);
}